
ALTER   PROC sp_ct_mkg_save_forecast_details(
 
 @SALES_PERSON VARCHAR(50),
 @CUSTOMER VARCHAR(100),
 @PRODUCT VARCHAR(100),
 @QTY INT,
 @UNIT_PRICE NUMERIC(9,2),
 @MONTH INT,
 @YEAR INT,
 @CONFIDENCE_LEVEL FLOAT,
 @ENDUSER VARCHAR(50) ) -- ADDED BY VARMA (08-SEP-2004)
 
 AS
 BEGIN
 
 	DECLARE @ROW_COUNT INT
 	
 	SELECT @ROW_COUNT = COUNT(*) FROM SALES_FORECAST_MASTER
 	WHERE SALES_PERSON = @SALES_PERSON 
 	AND CUSTOMER = @CUSTOMER
 	AND PRODUCT = @PRODUCT
 	AND SF_MONTH = @MONTH
 	AND SF_YEAR = @YEAR
	AND END_USER = @ENDUSER
 
 	IF @ROW_COUNT = 0 
 	BEGIN
 		INSERT INTO SALES_FORECAST_MASTER( SALES_PERSON, CUSTOMER, PRODUCT, SF_YEAR, SF_MONTH, 
 		SF_QTY, SF_UNIT_PRICE, CREATED_DT, MODIFIED_DT, SF_CONFIDENCE_LEVEL, END_USER ) 
 		VALUES( @SALES_PERSON, @CUSTOMER, @PRODUCT, @YEAR, @MONTH, @QTY, @UNIT_PRICE, 
 		CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, @CONFIDENCE_LEVEL,@ENDUSER )
 	END
  	ELSE
 	BEGIN
 		UPDATE SALES_FORECAST_MASTER SET SF_QTY = @QTY, SF_UNIT_PRICE = @UNIT_PRICE, MODIFIED_DT = CURRENT_TIMESTAMP, SF_CONFIDENCE_LEVEL = @CONFIDENCE_LEVEL
 		WHERE SALES_PERSON = @SALES_PERSON 
 		AND CUSTOMER = @CUSTOMER
 		AND PRODUCT = @PRODUCT
 		AND SF_MONTH = @MONTH
 		AND SF_YEAR = @YEAR
		AND END_USER = @ENDUSER
 	END
 
 END
 
